package com.cn.mybatis.dao;

import com.cn.mybatis.pojo.UserBean;
import org.apache.ibatis.annotations.*;
import org.mybatis.caches.redis.RedisCache;

import java.util.List;

@CacheNamespace // 开启二级缓存
public interface IUserDao {

    @Insert("insert into user(id, username) values(#{id}, #{username})")
    public void add(UserBean userBean);

    @Select("select * from user where id = #{id}")
    public UserBean getById(String id);

    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "username", property = "username"),
            @Result(column = "id", property = "orderList", javaType = List.class,
            one = @One(select = "com.cn.mybatis.dao.IOrderDao.getByUid")),
    })
    @Select("select * from user")
    public List<UserBean> getList();

    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "username", property = "username"),
            @Result(column = "id", property = "roleList", javaType = List.class,
                    one = @One(select = "com.cn.mybatis.dao.IRoleDao.getListByUid")),
    })
    @Select("select * from user")
    public List<UserBean> getListAndRole();

}
